home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Interfaces&Libraries / Universal / Interfaces / PInterfaces / Endian.p < prev    next >
Encoding:
Text File  |  1998-08-17  |  5.6 KB  |  200 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        Endian.p
  3.  
  4.      Contains:    QuickTime Interfaces
  5.  
  6.      Version:    Technology:    QuickTime 3.0
  7.                  Release:    Universal Interfaces 3.2
  8.  
  9.      Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. }
  17. {$IFC UNDEFINED UsingIncludes}
  18. {$SETC UsingIncludes := 0}
  19. {$ENDC}
  20.  
  21. {$IFC NOT UsingIncludes}
  22.  UNIT Endian;
  23.  INTERFACE
  24. {$ENDC}
  25.  
  26. {$IFC UNDEFINED __ENDIAN__}
  27. {$SETC __ENDIAN__ := 1}
  28.  
  29. {$I+}
  30. {$SETC EndianIncludes := UsingIncludes}
  31. {$SETC UsingIncludes := 1}
  32.  
  33. {$IFC UNDEFINED __CONDITIONALMACROS__}
  34. {$I ConditionalMacros.p}
  35. {$ENDC}
  36. {$IFC UNDEFINED __MACTYPES__}
  37. {$I MacTypes.p}
  38. {$ENDC}
  39.  
  40.  
  41. {$PUSH}
  42. {$ALIGN MAC68K}
  43. {$LibExport+}
  44.  
  45. {
  46.     This file provides Endian Flipping routines for dealing with converting data
  47.     between Big-Endian and Little-Endian machines.  These routines are useful
  48.     when writing code to compile for both Big and Little Endian machines and  
  49.     which must handle other endian number formats, such as reading or writing 
  50.     to a file or network packet.
  51.     
  52.     These routines are named as follows:
  53.     
  54.         Endian<U><W>_<S>to<D>
  55.  
  56.     where
  57.         <U>    is whether the integer is signed ('S') or unsigned ('U')
  58.         <W> is integer bit width: 16, 32, or 64 
  59.         <S> is the source endian format: 'B' for big, 'L' for little, or 'N' for native
  60.         <D> is the destination endian format: 'B' for big, 'L' for little, or 'N' for native
  61.     
  62.     For example, to convert a Big Endian 32-bit unsigned integer to the current native format use:
  63.         
  64.         long i = EndianU32_BtoN(data);
  65.         
  66.     This file is set up so that the function macro to nothing when the target runtime already
  67.     is the desired format (e.g. on Big Endian machines, EndianU32_BtoN() macros away).
  68.             
  69.     If long long's are not supported, you cannot get 64-bit quantities as a single value.
  70.     The macros are not defined in that case.
  71.     
  72.     
  73.     
  74.                                 <<< W A R N I N G >>>
  75.     
  76.     It is very important not to put any autoincrements inside the macros.  This 
  77.     will produce erroneous results because each time the address is accessed in the macro, 
  78.     the increment occurs.
  79.     
  80.  }
  81. FUNCTION EndianS16_BtoN(value: SInt16): SInt16; C;
  82. FUNCTION EndianS16_NtoB(value: SInt16): SInt16; C;
  83. FUNCTION EndianS16_LtoN(value: SInt16): SInt16; C;
  84. FUNCTION EndianS16_NtoL(value: SInt16): SInt16; C;
  85. FUNCTION EndianS16_LtoB(value: SInt16): SInt16; C;
  86. FUNCTION EndianS16_BtoL(value: SInt16): SInt16; C;
  87. FUNCTION EndianU16_BtoN(value: UInt16): UInt16; C;
  88. FUNCTION EndianU16_NtoB(value: UInt16): UInt16; C;
  89. FUNCTION EndianU16_LtoN(value: UInt16): UInt16; C;
  90. FUNCTION EndianU16_NtoL(value: UInt16): UInt16; C;
  91. FUNCTION EndianU16_LtoB(value: UInt16): UInt16; C;
  92. FUNCTION EndianU16_BtoL(value: UInt16): UInt16; C;
  93. FUNCTION EndianS32_BtoN(value: SInt32): SInt32; C;
  94. FUNCTION EndianS32_NtoB(value: SInt32): SInt32; C;
  95. FUNCTION EndianS32_LtoN(value: SInt32): SInt32; C;
  96. FUNCTION EndianS32_NtoL(value: SInt32): SInt32; C;
  97. FUNCTION EndianS32_LtoB(value: SInt32): SInt32; C;
  98. FUNCTION EndianS32_BtoL(value: SInt32): SInt32; C;
  99. FUNCTION EndianU32_BtoN(value: UInt32): UInt32; C;
  100. FUNCTION EndianU32_NtoB(value: UInt32): UInt32; C;
  101. FUNCTION EndianU32_LtoN(value: UInt32): UInt32; C;
  102. FUNCTION EndianU32_NtoL(value: UInt32): UInt32; C;
  103. FUNCTION EndianU32_LtoB(value: UInt32): UInt32; C;
  104. FUNCTION EndianU32_BtoL(value: UInt32): UInt32; C;
  105. FUNCTION EndianS64_BtoN(value: SInt64): SInt64; C;
  106. FUNCTION EndianS64_NtoB(value: SInt64): SInt64; C;
  107. FUNCTION EndianS64_LtoN(value: SInt64): SInt64; C;
  108. FUNCTION EndianS64_NtoL(value: SInt64): SInt64; C;
  109. FUNCTION EndianS64_LtoB(value: SInt64): SInt64; C;
  110. FUNCTION EndianS64_BtoL(value: SInt64): SInt64; C;
  111. FUNCTION EndianU64_BtoN(value: UInt64): UInt64; C;
  112. FUNCTION EndianU64_NtoB(value: UInt64): UInt64; C;
  113. FUNCTION EndianU64_LtoN(value: UInt64): UInt64; C;
  114. FUNCTION EndianU64_NtoL(value: UInt64): UInt64; C;
  115. FUNCTION EndianU64_LtoB(value: UInt64): UInt64; C;
  116. FUNCTION EndianU64_BtoL(value: UInt64): UInt64; C;
  117. {
  118.    These types are used for structures that contain data that is
  119.    always in BigEndian format.  This extra typing prevents little
  120.    endian code from directly changing the data, thus saving much
  121.    time in the debugger.
  122. }
  123. {$IFC TARGET_RT_LITTLE_ENDIAN }
  124.  
  125. TYPE
  126.     BigEndianLongPtr = ^BigEndianLong;
  127.     BigEndianLong = RECORD
  128.         bigEndianValue:            LONGINT;
  129.     END;
  130.  
  131.     BigEndianUnsignedLongPtr = ^BigEndianUnsignedLong;
  132.     BigEndianUnsignedLong = RECORD
  133.         bigEndianValue:            UInt32;
  134.     END;
  135.  
  136.     BigEndianShortPtr = ^BigEndianShort;
  137.     BigEndianShort = RECORD
  138.         bigEndianValue:            INTEGER;
  139.     END;
  140.  
  141.     BigEndianUnsignedShortPtr = ^BigEndianUnsignedShort;
  142.     BigEndianUnsignedShort = RECORD
  143.         bigEndianValue:            UInt16;
  144.     END;
  145.  
  146.     BigEndianFixedPtr = ^BigEndianFixed;
  147.     BigEndianFixed = RECORD
  148.         bigEndianValue:            Fixed;
  149.     END;
  150.  
  151.     BigEndianUnsignedFixedPtr = ^BigEndianUnsignedFixed;
  152.     BigEndianUnsignedFixed = RECORD
  153.         bigEndianValue:            UnsignedFixed;
  154.     END;
  155.  
  156.     BigEndianOSTypePtr = ^BigEndianOSType;
  157.     BigEndianOSType = RECORD
  158.         bigEndianValue:            OSType;
  159.     END;
  160.  
  161. {$ELSEC}
  162.  
  163. TYPE
  164.     BigEndianLong                        = LONGINT;
  165.     BigEndianUnsignedLong                = UInt32;
  166.     BigEndianShort                        = INTEGER;
  167.     BigEndianUnsignedShort                = UInt16;
  168.     BigEndianFixed                        = Fixed;
  169.     BigEndianUnsignedFixed                = UnsignedFixed;
  170.     BigEndianOSType                        = OSType;
  171. {$ENDC}  {TARGET_RT_LITTLE_ENDIAN}
  172.  
  173.  
  174.  
  175.  
  176.  
  177. {
  178.     Implement low level ≈_Swap functions.
  179.     
  180.         extern UInt16 Endian16_Swap(UInt16 value);
  181.         extern UInt32 Endian32_Swap(UInt32 value);
  182.         extern UInt64 Endian64_Swap(UInt64 value);
  183.         
  184.     Note: Depending on the processor, you might want to implement
  185.           these as function calls instead of macros.
  186.     
  187. }
  188.  
  189.  
  190. {$ALIGN RESET}
  191. {$POP}
  192.  
  193. {$SETC UsingIncludes := EndianIncludes}
  194.  
  195. {$ENDC} {__ENDIAN__}
  196.  
  197. {$IFC NOT UsingIncludes}
  198.  END.
  199. {$ENDC}
  200.